﻿namespace Furesoft.WPF.Game
{
    using System;
    using System.Windows;
    using System.Windows.Threading;

    public class GameEngine
    {
        #region Fields

        private readonly DispatcherTimer dt;

        #endregion

        #region Constructors and Destructors

        public GameEngine(Game g, Window window)
        {
            this.Game = g;
            this.Window = window;
            this.Game.Window = window;

            this.dt = new DispatcherTimer();
            this.dt.Interval = new TimeSpan(1000);
            this.dt.Tick += this.dt_Tick;

            this.Game.Initialize();
        }

        #endregion

        #region Public Properties

        public Game Game { get; set; }

        public Window Window { get; set; }

        #endregion

        #region Public Methods and Operators

        public void Start()
        {
            this.dt.Start();
        }

        public void Stop()
        {
            this.dt.Stop();
        }

        #endregion

        #region Methods

        private void dt_Tick(object sender, EventArgs e)
        {
            this.Game.Update();
            this.Game.Draw();
        }

        #endregion
    }
}